package com.hunttown.mes.common.utils;

import java.util.Random;

/**
 * created by hunttown on 2017/7/27
 */
public class GetRandomUtils {

    // 随机数（数字、字母混合）
    public static String GetRandom(Integer length) {
        StringBuilder val = new StringBuilder();
        Random random = new Random();

        //参数length，表示生成几位随机数
        for (int i = 0; i < length; i++) {

            String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
            //输出字母还是数字
            if ("char".equalsIgnoreCase(charOrNum)) {
                //输出是大写字母还是小写字母
                int temp = random.nextInt(2) % 2 == 0 ? 65 : 97;
                val.append((char) (random.nextInt(26) + temp));
            } else if ("num".equalsIgnoreCase(charOrNum)) {
                val.append(String.valueOf(random.nextInt(10)));
            }
        }
        return val.toString();
    }

    // 随机数（字母）
    public static String GetRandomLetter(Integer length) {
        StringBuilder val = new StringBuilder();
        Random random = new Random();

        //参数length，表示生成几位随机数
        for (int i = 0; i < length; i++) {
            //输出是大写字母还是小写字母
            int temp = random.nextInt(2) % 2 == 0 ? 65 : 97;
            val.append((char) (random.nextInt(26) + temp));
        }

        return val.toString();
    }

    // 随机数（数字）
    public static String GetRandomNumber(Integer length) {
        StringBuilder val = new StringBuilder();
        Random random = new Random();

        //参数length，表示生成几位随机数
        for (int i = 0; i < length; i++) {
            val.append(String.valueOf(random.nextInt(10)));
        }

        return val.toString();
    }

    /**
     * 得到一个 M 以内的随机数
     */
    public static int GetRandomByRange(int maxM) {
        return (int) (Math.random() * maxM);
    }

    public static void main(String[] args) {

        //Random random = new Random();
        //System.out.println("100以内随机数：" + random.nextInt(100));
        //System.out.println("200以内随机数：" + random.nextInt(200));

        /*
        for (int j = 0; j < 100; j++) {
            Integer k = Integer.parseInt(GetRandomNumber(2));
            if (k > 10 && k < 20) {
                System.out.println(k);
                break;
            }
        }
        */

        String message = "FEFEFE68436589280000689106363833373333FE16";
        for (int i = 0; i < 10; i++) {
            if (message.startsWith("FE")) {
                message = message.substring(2);
            } else {
                break;
            }
        }
        System.out.println(message);
    }
}
